package com.itheima.day08.myTreeSet.test6;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        TreeSet<ReportCard> treeSet = new TreeSet<>(new Comparator<ReportCard>(){
            @Override
            public int compare(ReportCard t1, ReportCard t2) {
                double difference = t1.getSum() - t2.getSum();
                difference = difference == 0 ? t1.getLanguage() - t2.getLanguage() : difference;
                difference = difference == 0 ? t1.getMathematics() - t1.getMathematics() : difference;
                difference = difference == 0 ? t1.getEnglish() - t2.getEnglish() : difference;
                difference = difference == 0 ? t1.getName().compareTo(t2.getName()) : difference;
                return (int) difference;
            }
        });

        ReportCard rc1 = new ReportCard("张三",84,99,100);
        ReportCard rc2 = new ReportCard("李四",75,100,99);
        ReportCard rc3 = new ReportCard("王五",100,60,40);

        treeSet.add(rc1);
        treeSet.add(rc2);
        treeSet.add(rc3);

        Iterator<ReportCard> it = treeSet.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }


    }
}
